import 'package:flutter/material.dart';

class NetworkImageWidget extends StatefulWidget {
  final String imgUrl;
  final String placeHolderAsset;
  final double? height;
  final double? width;

  const NetworkImageWidget({
    Key? key,
    required this.placeHolderAsset,
    required this.imgUrl,
    this.height,
    this.width,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _NetworkImageWidgetState(
      placeHolderAsset,
      imgUrl,
      height,
      width,
    );
  }
}

class _NetworkImageWidgetState extends State<NetworkImageWidget> {
  late String imgUrl;
  late String placeHolderAsset;
  double? height;
  double? width;
  late Image img, netImg;

  _NetworkImageWidgetState(
    this.placeHolderAsset,
    this.imgUrl,
    this.height,
    this.width,
  );

  @override
  void initState() {
    super.initState();
    double h = height ?? 80;
    double w = width ?? 80;
    img = Image.asset(
      placeHolderAsset,
      height: h,
      width: w,
      fit: BoxFit.cover,
    );
    try {
      netImg = Image.network(
        imgUrl,
        height: h,
        width: w,
        fit: BoxFit.cover,
      );
    } on Exception catch (e) {
      debugPrint(e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[img, netImg],
    );
  }
}
